package com.jin.webvideo.base.linkedfile.io;

import java.io.DataInputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

public class SeekableDataInputStream extends DataInputStream implements Seekable{
    private Seekable seeker;

    public SeekableDataInputStream(SeekableInputStream in) {
        super(in);
        this.seeker = in;
    }

    /**
     * 读取无符号int
     * @return
     * @throws IOException
     */
    public long readUnsignedInt() throws IOException {
        return Integer.toUnsignedLong(readInt());
    }

    public String readUTFBlockByUnsignedShort() throws IOException {
        int len = this.readUnsignedShort();
        byte[] bs = new byte[len];
        this.read(bs);
        return new String(bs, 0, len, StandardCharsets.UTF_8);
    }

    @Override
    public void seek(long position) throws IOException {
        seeker.seek(position);
    }
}
